package com.itheima.controller;

import com.itheima.domain.vo.Result;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;


/**
 * @author: Sch
 * @Date: 2025/07/16 9:01
 * @Description:
 */
public class SessionController {

    @GetMapping("c1")
    public Result cookie1(HttpServletResponse response){
        response.addCookie(new Cookie("username","itheima"));
        return Result.success();
    }
    @GetMapping("c2")
    public Result cookie2(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies){
            if (cookie.getName().equals("username")){
                System.out.println("username: "+ cookie.getValue());
            }
        }
        return Result.success();
    }
}
